Skip to content

Conversation

@Ameausoone
Copy link
Contributor

@Ameausoone Ameausoone commented Feb 7, 2025

Description

This pull request introduces new configuration variables for managing GKE backups:

  • backup_cron_schedule: Define backup scheduling as per a cron expression.
  • backup_rpo_target_in_minutes: Configure the Recovery Point Objective (RPO).
  • backup_config: Specify which volumes or secrets to back up.
  • backup_retain_days: Set the retention period for backups.
  • resource google_gke_backup_backup_plan to enable backup

Closes #2259

Checklist

  • [~] Tests added or updated, as applicable.
    No tests added, but I tested this PR manually, tests seems to not be designed to check other resources than the GKE cluster.
  • Documentation updated to reflect new configurations.
  • Verified and validated new configurations across GKE deployments.

By the way

Integration tests are designed from the ground to be executed in a organisation (which is totally relevant), but it could be difficult (even for professional) to get project creation rights in an organisation. It would be handy to have at least a procedure to execute the tests, in a regular project.

@Ameausoone Ameausoone requested review from a team, apeabody and ericyz as code owners February 7, 2025 08:59
Introduce new variables for GKE backup configuration, including `backup_cron_schedule`, `backup_rpo_target_in_minutes`, `backup_config`, and `backup_retain_days`. These new settings enable backup schedule definition, RPO configuration, volume data and secrets backup options, and backup retention period definition.
@apeabody
Copy link
Collaborator

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable feature by adding GKE backup configuration to the module. The changes are consistently applied across various modules, which is great. However, I've found a critical issue in the Terraform configuration for the google_gke_backup_backup_plan resource. The use of two dynamic "backup_schedule" blocks is invalid and will cause Terraform to fail. I have provided a detailed comment with a suggested fix to address this. Additionally, I've included a minor suggestion to simplify a validation condition for one of the new variables.

Comment on lines +16 to +31
dynamic "backup_schedule" {
for_each = var.backup_cron_schedule != null ? [var.backup_cron_schedule] : []
content {
cron_schedule = backup_schedule.value
}
}

dynamic "backup_schedule" {
# If both backup_schedule and rpo_config are specified, backup_schedule have the precedence
for_each = var.backup_rpo_target_in_minutes != null && var.backup_cron_schedule ==null ? [var.backup_rpo_target_in_minutes] : []
content {
rpo_config {
target_rpo_minutes = backup_schedule.value
}
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The use of two dynamic "backup_schedule" blocks is invalid in Terraform and will cause a configuration parsing error, as a resource can only have one dynamic block of a given name. To correctly implement the mutual exclusivity and precedence for cron_schedule and rpo_config, you should use a single dynamic "backup_schedule" block with nested logic. I've also added a newline at the end of the file, which is a good practice.

  dynamic "backup_schedule" {
    for_each = var.backup_cron_schedule != null || var.backup_rpo_target_in_minutes != null ? [1] : []

    content {
      cron_schedule = var.backup_cron_schedule

      dynamic "rpo_config" {
        for_each = var.backup_cron_schedule == null && var.backup_rpo_target_in_minutes != null ? [1] : []
        content {
          target_rpo_minutes = var.backup_rpo_target_in_minutes
        }
      }
    }
  }

type = number
default = null
validation {
condition = var.backup_rpo_target_in_minutes == null || try(var.backup_rpo_target_in_minutes >= 60 && var.backup_rpo_target_in_minutes <= 86400, false)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The try() function in this validation condition is unnecessary. Terraform's || operator uses short-circuit evaluation, so if var.backup_rpo_target_in_minutes is null, the expression on the right of the || will not be evaluated, preventing an error. You can simplify this condition.

    condition     = var.backup_rpo_target_in_minutes == null || (var.backup_rpo_target_in_minutes >= 60 && var.backup_rpo_target_in_minutes <= 86400)

@apeabody apeabody changed the title feat(backup): add GKE backup configuration in the module feat(backup): add GKE backup configuration in the module Oct 30, 2025
@apeabody
Copy link
Collaborator

(remove extra space from PR for commitlint)

Copy link
Collaborator

@apeabody apeabody left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @Ameausoone!

Prior to review, can you please run make build and the other items listed in the Lint output, and add to this change. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for google_gke_backup_backup_plan

2 participants